package com.dms.modules.admin.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;

@Data
@TableName("admin")
@ApiModel(value = "Admin对象", description = "管理员")
public class Admin implements UserDetails {
    
    @TableId(type = IdType.AUTO)
    @ApiModelProperty("管理员ID")
    private Long id;
    
    @TableField(exist = false)
    @ApiModelProperty("用户名")
    private String username;
    
    @TableField(exist = false)
    @ApiModelProperty("密码")
    private String password;
    
    @ApiModelProperty("昵称")
    private String nickname;
    
    @ApiModelProperty("头像")
    private String avatar;
    
    @ApiModelProperty("邮箱")
    private String email;
    
    @ApiModelProperty("手机号")
    private String phone;
    
    @ApiModelProperty("状态：0-禁用 1-正常")
    private Integer status;
    
    @ApiModelProperty("关联的用户ID")
    private Long userId;
    
    @ApiModelProperty("创建时间")
    private Date createTime;
    
    @ApiModelProperty("更新时间")
    private Date updateTime;
    
    @TableLogic
    @ApiModelProperty("是否删除")
    private Integer deleted;
    
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.singletonList(new SimpleGrantedAuthority("ROLE_ADMIN"));
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return status != null && status == 1;
    }
} 